package com.sanjiahantang.youjiaclient.module.programmeprice.modles.impl;

import android.app.Activity;
import android.content.Context;

import com.sanjiahantang.youjiaclient.base.BaseApplication;
import com.sanjiahantang.youjiaclient.base.CallBack;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.config.StaticValue;
import com.sanjiahantang.youjiaclient.http.BaseDelegate;
import com.sanjiahantang.youjiaclient.http.OkHttpClientManager;
import com.sanjiahantang.youjiaclient.module.common.beans.StringBean;
import com.sanjiahantang.youjiaclient.module.common.beans.StringCheckBean;
import com.sanjiahantang.youjiaclient.module.programmeprice.beans.ProgramAddOrderListBean;
import com.sanjiahantang.youjiaclient.module.programmeprice.beans.ProgramBean;
import com.sanjiahantang.youjiaclient.module.programmeprice.beans.ProgramOrderListBean;
import com.sanjiahantang.youjiaclient.module.programmeprice.modles.IProgramPriceModel;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/10/25.
 */

public class ProgramPriceModel implements IProgramPriceModel,StaticValue{
    @Override
    public void OnLoadBaoJList(final Context context, Map<String, Object> params, final CallBack<ProgramBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/project/price/phone/customer/findProjectPlanInfoForCustomer",params,new BaseDelegate.ResultCallback<ProgramBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ProgramBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });

    }
   //增项清单
    @Override
    public void addPriceOnLoadBaoJList(final Context context, Map<String, Object> params, final CallBack<ProgramAddOrderListBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/order/phone/findIncreaseListForCustomer",params,new BaseDelegate.ResultCallback<ProgramAddOrderListBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ProgramAddOrderListBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void SavePricePlanInfo(final Context context, Object params, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/project/price/phone/customer/saveProjectPlanPriceInfo",params,new BaseDelegate.ResultCallback<StringBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void checkVersionInfo(final Context context, Map<String, Object> params, final CallBack<StringCheckBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/project/price/phone/customer/checkVersion",params,new BaseDelegate.ResultCallback<StringCheckBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringCheckBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }

    @Override
    public void findPlaceOrder(final Context context, Map<String, Object> params, final CallBack<ProgramBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/project/price/phone/customer/findPlaceOrder",params,new BaseDelegate.ResultCallback<ProgramBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ProgramBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }
    //提交订单
    @Override
    public void creatOrderPhoneForPlan(final Context context, Object params, final int ppId,final int type, final CallBack<StringBean> callBack) {
        OkHttpClientManager.postJson(context, ConfigValue.API_URL + "/order/phone/createOrderPhoneForPlan",params,new BaseDelegate.ResultCallback<StringBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                if (response != null && response.getCode() == RESPONSE_CODE_SUC){
//                    Map<String,String> param = new HashMap<String, String>();
//                    param.put(KEY_TOKEN,ConfigValue.DATA_KEY);
//                    param.put("ppId",String.valueOf(ppId));
//                    param.put("type",String.valueOf(type));
//                    param.put("wang",response.getData());
//                    updateProjectPriceInfoIsPlaceAnOrder(context,param,response.getData(),callBack);
                    callBack.onSuccess(response,context,response);
                    BaseApplication.addActivity((Activity) context);
                 //   ((Activity) context).finish();
                }else{
                    callBack.onSuccess(response,context, tag);
                }
            }
        });
    }

    @Override
    public void findPlanInfo(final Context context, Map<String, String> param, final CallBack<ProgramOrderListBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/project/price/phone/customer/findPlanInfo",param,new BaseDelegate.ResultCallback<ProgramOrderListBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(ProgramOrderListBean response, Object tag) {
                callBack.onSuccess(response,context, tag);
            }
        });
    }


    public void updateProjectPriceInfoIsPlaceAnOrder(final Context context, Map<String, String> param, final String data, final CallBack<StringBean> callBack){
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/project/price/phone/customer/updateProjectPriceInfoIsPlaceAnOrder",param,new BaseDelegate.ResultCallback<StringBean>() {

            @Override
            public void onError(Request request, Object tag, Exception e) {
                callBack.onFailure(e.getMessage());
            }

            @Override
            public void onResponse(StringBean response, Object tag) {
                callBack.onSuccess(response,context, data);
            }
        });
    }
}
